<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="select2/select2.min.css"/>
	</head>
	<body>
		<select name="" id="my_sel" multiple="multiple">
			<option value="">请选择</option>
		</select>
		<button id="get_value">获取选中的值</button>
	</body>
	<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
	<script src="select2/select2.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var type_arr = [{"id":1,"name":"cheng"},{"id":2,"name":"zhan"},{"id":3,"name":"peng"}];
		function add_sel(){
			var str = "";
			for (var i=0;i<type_arr.length;i++) {
				str += "<option value='"+type_arr[i]["id"]+"'>"+type_arr[i]["name"]+"</option>"; 
			}
			$("#my_sel").append(str);
		}
		setTimeout(function(){
			add_sel();
			$('#my_sel').select2({
				placeholder: "Select a state", //placeholder
				maximumSelectionLength:2 //最多可以选择的数量
			});
		},200)
		$("#get_value").click(function(){
			var cardTypeW = $("#my_sel").val();
			console.log(cardTypeW);
		})
	</script>
</html>
